package com.example.wuren;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class BossPublish extends AppCompatActivity {

    private Spinner jobDropdown;
    private Spinner salaryDropdown;
    private EditText requirementInput;
    private Button publishButton;

    private String[] jobOptions = {"销售", "软件工程师"};
    private String[] salaryOptions = {"1500~2000元", "2000~3000元", "3000~5000元"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.boss_publish);

        // 初始化招聘岗位下拉框
        jobDropdown = findViewById(R.id.job_dropdown);
        ArrayAdapter<String> jobAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, jobOptions);
        jobAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        jobDropdown.setAdapter(jobAdapter);

        // 初始化薪资待遇下拉框
        salaryDropdown = findViewById(R.id.salary_dropdown);
        ArrayAdapter<String> salaryAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, salaryOptions);
        salaryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        salaryDropdown.setAdapter(salaryAdapter);

        // 初始化职位要求输入框
        requirementInput = findViewById(R.id.requirement_input);

        // 初始化发布按钮
        publishButton = findViewById(R.id.publish_button);
        publishButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取选择的招聘岗位
                String selectedJob = jobDropdown.getSelectedItem().toString();
                // 获取选择的薪资待遇
                String selectedSalary = salaryDropdown.getSelectedItem().toString();
                // 获取职位要求输入内容
                String requirement = requirementInput.getText().toString();

                // 这里可以添加实际的网络请求代码来将信息发送到服务器，实现真正的发布功能
                // 目前只是简单地提示发布成功
                if (selectedJob.isEmpty() || selectedSalary.isEmpty() || requirement.isEmpty()) {
                    Toast.makeText(BossPublish.this, "请填写完整的岗位信息", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(BossPublish.this, "岗位发布成功！\n招聘岗位：" + selectedJob +
                            "\n薪资待遇：" + selectedSalary + "\n职位要求：" + requirement, Toast.LENGTH_SHORT).show();
                    // 跳转到boss_list页面
                    Intent intent = new Intent(BossPublish.this, BossList.class);
                    startActivity(intent);
                }
            }
        });

        // 底部导航栏点击事件处理
        findViewById(R.id.bottom_navigation).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int id = v.getId();
                if (id == R.id.bottom_navigation) {
                    // 这里可以根据不同的子项ID进行不同的操作
                    Toast.makeText(BossPublish.this, "底部导航栏被点击", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    // 底部导航栏子项点击事件处理方法
    public void onNavigationItemClick(View view) {
        int id = view.getId();
        // 使用if-else替代switch来避免“需要常量表达式”的错误
        if (id == R.id.bottom_navigation) {
            Toast.makeText(this, "你点击了底部导航栏的某个子项", Toast.LENGTH_SHORT).show();
        }
        // 可以继续添加其他子项的处理逻辑
    }
}